package chap10;

import chap10.Callbacks.Callee.closure;

public class Callbacks {
	interface Incrementable{
		void increment();
	}
	class MyIncrement{
		void increment(){
			System.out.println("other");
		}
		void f(MyIncrement mi){
			mi.increment();
		}
	}
	class Callee extends MyIncrement{
		private int i=0;
		public void increment(){
			super.increment();
			i++;
			System.out.println(i);
		}
		class closure implements Incrementable{

			@Override
			public void increment() {
				// TODO Auto-generated method stub
				Callee.this.increment();
			}
				
		}
		Incrementable getCallbacks(){
			 return new closure();
		 }
	}
	class Caller{
		private Incrementable incrementable;
		Caller(Incrementable cbn){
			this.incrementable=cbn;
		}
		void go(){
			incrementable.increment();
		}
	}
	public static void main(String[] args) {
		Callee c=new Callbacks().new Callee();
		c.increment();
		//Callee s=(Callee) new Callbacks().new Callee().getCallbacks();
		Incrementable cbn=c.getCallbacks();
		Caller ca=new Callbacks().new Caller(c.getCallbacks());
		ca.go();
		
	}

}
